<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/8/16
  Time: 14:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>项目办理结果公示</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.min.css">
    <script src="${pageContext.request.contextPath}/js/jquery-3.6.0.min.js"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
    <!-- Bootstrap -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.css"/>
    <%--引入echarts--%>
    <script src="${pageContext.request.contextPath}/js/echarts.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/index.css">
    <%--    revealFull--%>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/item/revealFull.css">
</head>
<body>
<%@include file="../pub/header.jsp" %>
<div class="header">
    <div class="nav">
        <div class="container">
            <div class="row">
                <a class="col-md-3 col-xs-6" href="${pageContext.request.contextPath}/index">首&nbsp;页</a>
                <a class="col-md-3 col-xs-6" href="${pageContext.request.contextPath}/user/news">新闻资讯</a>
                <a class="col-md-3 col-xs-6" href="${pageContext.request.contextPath}/re_approve/item">办事大厅</a>
                <a class="col-md-3 col-xs-6 active"
                   href="${pageContext.request.contextPath}/item/revealFull">公示信息</a>
            </div>
        </div>
    </div>
</div>
<br>
<br>
<div class="container">
    <div class="row">
        <div class="reveal_fulls">
            <div class="lm_tit">
                <span class="one">项目办理结果公示</span>
                <a href="javaScript:history.back(-1)">返回</a>
            </div>
            <div style="display:inline;width:50%">
                <p style="display:inline-block;margin-top:30px;">
                    <span style="margin-left:10px;font-weight: bold;">审批结果</span>
                    <select id="itemState" style="height:30px;width:200px">
                        <option value="">全&nbsp;&nbsp;&nbsp;部</option>
                        <option value="3">通&nbsp;&nbsp;&nbsp;过</option>
                        <option value="2">待&nbsp;&nbsp;&nbsp;批</option>
                        <option value="1">未通过</option>
                    </select>
                </p>
            </div>
            <button type="button" onclick="ajaxList();" style="margin-left:30px;outline-style: none"
                    class="btn btn-success">查询
            </button>
            <div class="bs-example" data-example-id="striped-table">
                <table class="table table-striped">
                    <thead>
                    <tr>
                        <th>项目代码</th>
                        <th>项目名称</th>
                        <th>审批事项</th>
                        <th>审批时间</th>
                        <th>审批结果</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tbody id="leader_info_body">
                    </tbody>
                </table>
                <nav aria-label="Page navigation">
                    <ul class="pagination">
                        <li>
                            <a  aria-label="Previous" onclick="upPage()">
                                <span aria-hidden="true"><i class="iconfont">&#xe671;</i></span>
                            </a>
                        </li>
                    </ul>
                    <ul class="pagination" id="pageLi">
                    </ul>
                    <ul class="pagination">
                        <li>
                            <a  aria-label="Next" onclick="nextPage()">
                                <span aria-hidden="true"><i class="iconfont">&#xe673;</i></span>
                            </a>
                        </li>
                    </ul>
                </nav>
            </div>
        </div>
    </div>
</div>
<%@include file="../pub/footer.jsp" %>
<script>
    var pageId = 1
    $(function () {
        ajaxList(pageId)
    })

    function setNullToEmpty(val) {//将所有空数据都转为'-'
        if (val === null || val === 'null' || val === '' || val == undefined || val == 'undefined') {
            return '-';
        }
        return val;
    }

    var totalPage = 1
    var pageNum = 1;

    function getPage(par) {
        ajaxList($(par).text())
        pageNum = $(par).text();
    }

    function nextPage() {
        // let next = 1;
        // let top = Number(totalPage) + Number(next)
        // pageNum = Number(pageNum) + Number(next)
        if (totalPage <= pageId) {
            return
        } else {

            ajaxList(++pageId)
        }
    }

    function upPage() {
        // let next = 1;
        // let top = Number(totalPage) - Number(next)
        // pageNum = Number(pageNum) - Number(next)
        // console.info(pageNum > top)
        if (1 >= pageId) {
            return
        } else {
            ajaxList(--pageId)
        }
    }

    function ajaxList(next) {
        var itemName = $("#itemName").val();
        var itemState = $("#itemState").val();
        var pageId = next
        $.ajax({
            type: 'get',
            url: "${pageContext.request.contextPath}/re_approve/reveal_full",
            data: {
                "itemName": itemName,
                "itemState": itemState,
                "pageId": pageId,
            },
            success: function (result) {
                console.log(123);
                var rows = result.list;//得到数据列
                totalPage = result.totalPage;//得到数据列
                var html = '';
                var pagrhtml = '';
                for (var i = 0; i < rows.length; i++) {
                    html += ' <tr onclick=location.href="${pageContext.request.contextPath}/re_approve/approveInfo?ItemId=' + rows[i].item.id + '">';
                    var projectCode = "-";
                    var regionApproveName = "-";
                    if (rows[i].item != null) {
                        projectCode = setNullToEmpty(rows[i].item.code);
                        regionApproveName = setNullToEmpty(rows[i].item.name);
                    }
                    html += '<td>' + projectCode + '</td>';
                    html += '<td>' + regionApproveName + '</td>';
                    var approvalmatters = setNullToEmpty(rows[i].message);
                    html += '<td>' + approvalmatters + '</td>';
                    var regionDate = setNullToEmpty(rows[i].processingTime);
                    let date = getDate(regionDate);
                    if (date.match("N")) {
                        date=""
                    }
                    html += '<td>' + date + '</td>';
                    if(rows[i].status == 1){
                        var itemState = setNullToEmpty('不通过');
                    }
                    if(rows[i].status == 2){
                        var itemState = setNullToEmpty('待&nbsp;&nbsp;&nbsp;批');
                    }
                    if(rows[i].status == 3){
                        var itemState = setNullToEmpty('通&nbsp;&nbsp;&nbsp;过');
                    }
                    html += '<td>' + itemState + '</td>';
                    html += '</tr>';
                }
                if (rows.length == 0) {
                    html += '<tr><td></td><td></td><td></td><td></td><td>无数据</td><td></td><td></td><td></td></tr>';
                }
                console.log(pageId+"//");
                if (totalPage != 0) {
                    console.log(pageId+"///")
                    for (var i = 1; i <= totalPage; i++) {
                        console.log(pageId);
                        if (pageId==i){
                            pagrhtml += '<li class="active"><a onclick="getPage(this)">' + i + '</a></li>'
                        }
                        else {

                            pagrhtml += '<li ><a onclick="getPage(this)">' + i + '</a></li>'
                        }

                    }
                }
                $("#leader_info_body").html(html);
                $("#pageLi").html(pagrhtml);
            }
        });
    }

    function getDate(time) {
        let a = new Date(time).getTime();
        const date = new Date(a);
        const Y = date.getFullYear() + '-';
        const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
        const D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + '  ';
        const h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
        const m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
        const s = date.getSeconds(); // 秒
        const dateString = Y + M + D + h + m + s;
        return dateString;
    }
</script>
</body>
</html>
